package com.itheima.jdbc;

/*
 *  JDBC 快速入门
 * */

import org.junit.Test;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class JDBCDemo6_UserLogin {

    @Test
    public void testDML() throws Exception {

        // 2.获取链接
        String url ="jdbc:mysql://localhost:3306/db1?useSSL=false&serverTimezone=UTC";
        String username ="root";
        String password ="dzl123";
        Connection conn = DriverManager.getConnection(url,username,password);

        // 接受用户输入 用户名和密码
        String name="dadfafdsa";
        String pwd="' or'1'='1";

        String sql="select * from tb_user where username ='"+name+"'and password='"+pwd+"'";

        //获取stmt对象
        Statement stmt = conn.createStatement();



        // 执行sql
        ResultSet rs = stmt.executeQuery(sql);

        // 判断登录是否成功
        if (rs.next()){
            System.out.println("登录成功");
        }else {
            System.out.println("登录失败");
        }


        //7.释放资源
        rs.close();
        stmt.close();
        conn.close();

    }


}
